package com.yulongtian.interviewWorks.day20220826;

/**
 * https://leetcode.cn/problems/exchange-lcci/submissions/
 * @author YulongTian
 * @date 2022/8/26 - 14:02
 */
public class Test04 {
    public static void main(String[] args) {
        System.out.println(exchangeBits(3));
    }

    public static int exchangeBits(int num) {
        String s = Integer.toBinaryString(num);
        if(s.length()%2==1){
            s="0"+s;
        }
        StringBuilder res=new StringBuilder();
        for(int i=s.length()-1;i>=0;i-=2){
            res.append(s.charAt(i-1));
            res.append(s.charAt(i));
        }
        return Integer.parseInt(res.reverse().toString(),2);
    }
}
